package com.fm.base.database.domain;

import org.joda.time.DateTime;

/**
 * @author leo.li
 */
public abstract class DBEntity<T> {
    private Object id;
    protected T content;
    private String md5;
    private DateTime createTime;
    private DateTime updateTime;

    public DBEntity() {
    }

    public DBEntity(T content) {
        setContent(content);
    }

    public DBEntity(Object id, T content) {
        setId(id);
        setContent(content);
    }

    public abstract String computeMd5();

    public Object getId() {
        return id;
    }

    public void setId(Object id) {
        this.id = id;
    }

    public abstract T getContent();

    public abstract void setContent(T content);

    public String getMd5() {
        return md5;
    }

    public void setMd5(String md5) {
        this.md5 = md5;
    }

    public DateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(DateTime createTime) {
        this.createTime = createTime;
    }

    public DateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(DateTime updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "{\n" +
            "\tid:" + id + ",\n" +
            "\tcontent:" + content + ",\n" +
            "\tmd5:\"" + (md5 == null ? computeMd5() : md5) + "\",\n" +
            "\tcreateTime:" + createTime.toString("yyyy-MM-dd HH:mm:ss z") + ",\n" +
            "\tupdateTime:" + updateTime.toString("yyyy-MM-dd HH:mm:ss z") +
            "\n}";
    }
}
